Titanium.include('globals.js');

exports.parseJsonDate = function(jsonDate) {
    var offset = new Date().getTimezoneOffset() * 60000;
    var parts = /\/Date\((-?\d+)([+-]\d{2})?(\d{2})?.*/.exec(jsonDate);

    if (parts[2] == undefined)
      parts[2] = 0;

    if (parts[3] == undefined)
      parts[3] = 0;

   var date= new Date(+parts[1] + offset + parts[2]*3600000 + parts[3]*60000);
   var d = date.getDate();
   var m = date.getMonth()+1;
   var y = date.getFullYear();
   var hh = date.getHours();
   var mm = date.getMinutes();
   var ss = date.getSeconds();
   return '' + d +'/'+m +'/'+ y+' ' + hh +':'+mm +':'+ ss;
};


exports.GetJsonFunction= function(Jsonurl,param,onload_function,error_function)
{
	//Codestrong.ui.activityIndicator.showModal(Globals.loading, Globals.timeout, Globals.loadingTimeout);
	var xhr = Titanium.Network.createHTTPClient({
		
		   onload : function(e) 
		   {
		      // Titanium.API.info(this.responseText);
			   json = this.responseText;
			   json=json.replace('<string xmlns="http://tempuri.org/">', '');
			   json=json.replace('<?xml version="1.0" encoding="utf-8"?>', '');
			   json=json.replace('</string>', '');
			   json=json.replace(/(\r\n|\n|\r)/gm,"");
			   response = JSON.parse(json).OBJECT;
			   // Titanium.API.info(response);
			   //onload_function(this.responseText);
			   
			    onload_function({
					datajson :response,
				});
				
			   //Codestrong.ui.activityIndicator.hideModal();
		   },
		   onerror : function(e) {
		       error_function({
				  datajson:response
			   });
		   },
		   timeout : 5000
    
	});
	xhr.open("POST",Jsonurl);
	xhr.send(param);
	
};

